package org.pentaho.cubic.login.server;

import org.pentaho.cubic.login.client.ICubicLoginService;
import org.springframework.security.AuthenticationTrustResolver;
import org.springframework.security.AuthenticationTrustResolverImpl;
import org.springframework.security.context.SecurityContextHolder;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;


public class CubicLoginService extends RemoteServiceServlet implements ICubicLoginService {

	private static final long serialVersionUID = 6251967720481778058L;
	private AuthenticationTrustResolver resolver = new AuthenticationTrustResolverImpl();

	/**
	 * Note that this implementation is different from MantleServlet.isAuthenticated. This method must return false if the
	 * user is anonymous. That is not the case for MantleServlet.isAuthenticated.
	 */
	public boolean isAuthenticated() {
		return !resolver.isAnonymous(SecurityContextHolder.getContext().getAuthentication());
	}

}
